/*
Simple Forum Auto Poster.
Copyright (C) 2011 Gianni Van Hoecke.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gui.template;

import domain.DomainController;
import domain.template.Template;
import domain.ui.TemplateUI;
import java.awt.BorderLayout;
import java.awt.Toolkit;

/**
 *
 * @author Gianni Van Hoecke <gianni.vh@gmail.com>
 */
public class TemplateManagerContainer extends javax.swing.JFrame implements TemplateUI
{

    /** Creates new form TemplateManagerContainer */
    public TemplateManagerContainer()
    {
        initComponents();
        BorderLayout layout = (BorderLayout) getLayout();
        layout.setVgap(3);
        layout.setHgap(3);
        DomainController.getInstance().setTemplateUI(this);
        this.templatesListPanel1.loadList();
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("/data/icon.png"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        templatesListPanel1 = new gui.template.TemplatesListPanel();
        templateEditPanel1 = new gui.template.TemplateEditPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Manage templates");
        setMinimumSize(new java.awt.Dimension(600, 400));

        jSplitPane1.setLeftComponent(templatesListPanel1);
        jSplitPane1.setRightComponent(templateEditPanel1);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JSplitPane jSplitPane1;
    private gui.template.TemplateEditPanel templateEditPanel1;
    private gui.template.TemplatesListPanel templatesListPanel1;
    // End of variables declaration//GEN-END:variables

    public void loadList()
    {
        this.templatesListPanel1.loadList();
        this.templateEditPanel1.unload();
    }

    public void loadTemplate(Template template)
    {
        if(template != null)
            this.templateEditPanel1.loadTemplate(template);
    }

    public void setSelectedTemplate(String name)
    {
        this.templatesListPanel1.setSelectedTemplate(name);
    }

    public String getSelectedTemplate()
    {
        return this.templatesListPanel1.getSelectedTemplate();
    }

    public String getBody()
    {
        return this.templateEditPanel1.getBody();
    }
}